package com.zcxy.fast.utils;

import cn.hutool.core.collection.CollectionUtil;
import com.zcxy.fast.bean.TreeNode;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zcc
 * @date 2019-12-27
 */
public class TreeUtil {


    public static void deepGenTree(List<TreeNode> treeNodes, TreeNode parentNode) {
        List<TreeNode> treeVos = treeNodes.stream().filter(i -> {
            return i.getParentId().equals(parentNode.getKey());
        }).collect(Collectors.toList());
        if (CollectionUtil.isNotEmpty(treeVos)) {
            treeVos.forEach(i -> {
                deepGenTree(treeNodes, i);
            });
        }
        if (CollectionUtil.isNotEmpty(treeVos)) {
            parentNode.setChildren(treeVos);
        } else {
            parentNode.setChildren(null);
        }

    }

}
